package com.gzdh.device.system.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gzdh.device.comm.vo.Result;
import com.gzdh.device.system.entity.SysDepart;
import com.gzdh.device.system.model.SysDepartTreeModel;
import com.gzdh.device.system.service.SysDepartService;
import com.gzdh.device.system.util.FindsDepartsChildrenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("api/depart/v1")
public class SysDepartController {


    @Autowired
    SysDepartService sysDepartService;

    /**
     * 获取全部部门
     */
    @GetMapping("list")
    public Result<Object> list() {
        Result<Object> result = new Result<>();
        List<SysDepart> sysDepartList = sysDepartService.list(new QueryWrapper<SysDepart>().lambda().eq(SysDepart::isDelFlag, false));
        List<SysDepartTreeModel> listResult = FindsDepartsChildrenUtil.wrapTreeDataToTreeList(sysDepartList);
        result.setResult(listResult);
        return result;
    }

}
